package com.vd.wmt.resource;

import java.io.FileInputStream;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
 * @desc xls资源
 * @author tudongyun
 *
 */
public class XlsResource {
	private String fileName;
	private Workbook workBook;
	public String getFileName() {
		return fileName;
	}
	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
	public Workbook getWorkBook() throws Exception {
		synchronized (fileName) {
			if(workBook != null){
				return workBook;
			}
			FileInputStream fps = new FileInputStream(fileName);
			if(fileName.endsWith("xls")){
				workBook = new HSSFWorkbook(fps);
			}else{
				workBook = new XSSFWorkbook(fps);
			}
		}
		return workBook;
	}
	public XlsResource(String fileName) {
		this.fileName=fileName;
	}
}
